public class Test {
    public static void main(String[] args) {
        for (int i = 0; i <=999999 ; i++) {
            //先知道它是几位数
            int count = 0;
            int temp = i;
            while(temp != 0){
                count ++;       //一进来，temp不等于0；证明至少有一位数，所以count++
                temp = temp / 10;       //除以10，直到temp为0
            }
            //得到每一位数
            temp = i;
            int sum = 0;
            while(temp != 0){
                int j = temp % 10;
                sum += Math.pow(j,count);       //pow表示立方，表示j的count次方
                temp/=10;
            }
            if(sum == i){
                System.out.println(count +"位的自幂数为："+i);
            }
        }

    }
    public static void main1(String[] args) {
        int i = 0;
        for (i = 100; i <= 999; i++) {
            int g = i % 10;
            int s = i / 10 % 10;
            int b = i / 100;
            int sum = g*g*g+s*s*s+b*b*b;

            if(sum == i){
                System.out.print(i+" ");
            }
        }
    }
}
